package com.xbongbong.paas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

/**
 * @author zheng.li
 * @version v1.0
 * @date 2019/5/10 11:13
 * @since v1.0
 */
@Getter
public enum DownloadExcelTypeEnum {
    /**
     * 模板下载
     */
    TEMPLATE(0, "template", ""),
    /**
     * 错误excel下载
     */
    ERROR(1, "error", "enum.downloadExcelType.msg.error"),
    /**
     * 重复数据excel下载
     */
    UPDATE(2, "update", "enum.downloadExcelType.msg.update"),
    /**
     * 重复数据excel下载
     */
    NO_SIGN(3, "noSign", "enum.downloadExcelType.msg.noSign"),
    ;

    /**
     * 下载类型
     */
    private int type;
    /**
     * 名称
     */
    private String alias;
    /**
     * 提示信息
     */
    private String msg;

    DownloadExcelTypeEnum(int type, String alias, String msg) {
        this.type = type;
        this.alias = alias;
        this.msg = msg;
    }

    /**
     * 通过枚举 alias 获得枚举
     *
     * @param alias 枚举别名
     * @return DownloadExcelTypeEnum
     */
    public static DownloadExcelTypeEnum getByAlias(String alias) {
        for (DownloadExcelTypeEnum cacheCode : values()) {
            if (cacheCode.getAlias().equals(alias)) {
                return cacheCode;
            }
        }
        return TEMPLATE;
    }

    /**
     * 通过枚举 type 获得枚举
     *
     * @param type 枚举Code
     * @return DownloadExcelTypeEnum
     */
    public static DownloadExcelTypeEnum getByType(Integer type) {
        if (type == null) {
            return TEMPLATE;
        }
        for (DownloadExcelTypeEnum cacheCode : values()) {
            if (type.equals(cacheCode.getType())) {
                return cacheCode;
            }
        }
        return TEMPLATE;
    }

    public String getMsg() {
        return I18nMessageUtil.getMessage(msg);
    }
}
